package com.leetcode;

public class Date250714 {
    /**
     * 给定一个二进制数组 nums 和一个整数 k，如果可以翻转最多 k 个 0 ，则返回 数组中连续 1 的最大个数 。
     */
    public int longestOnes(int[] nums, int k) {
        int zero =0, len = 0, left = 0, right = -1;
        while(right < nums.length - 1){
            right++;
            if(right < nums.length && nums[right] == 0){
                zero++;
            }

                while(zero > k){
                   if(nums[left] == 0){
                       zero--;
                   }
                   left++;
                }
            len = Math.max(len, right - left + 1);
        }
        return len;
    }

    public static void main(String[] args) {
        Date250714 date250714 = new Date250714();
        System.out.println(date250714.longestOnes(new int[]{0,0,1,1}, 1));
        System.out.println(date250714.longestOnes(new int[]{1,1,1,0,0,0,1,1,1,1,0}, 2));
        System.out.println(date250714.longestOnes(new int[]{0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1}, 3));
    }
}
